package br.ujr.dynamicproxy;

import java.lang.reflect.Proxy;

import javax.persistence.EntityManager;

public class Decorator {
	
	public static <T> T withTransacao(Object target, Class<T> clazz, EntityManager em) {
		Class allInterfaces[] = new Class[]{clazz};
		TransacaoHandlerDynamicProxy transacaoDynamicProxy = new TransacaoHandlerDynamicProxy(target,em);
		ClassLoader classLoader = target.getClass().getClassLoader();
		return (T) Proxy.newProxyInstance(classLoader, allInterfaces, transacaoDynamicProxy);
	}

}
